package com.atguigu.gmall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.product.ProductSkuDetailFeignCilent;
import com.atguigu.gmall.feign.item.SkuDetailFeignClient;
import com.atguigu.gmall.item.vo.SkuDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class ItemController {
    @Autowired
    private SkuDetailFeignClient skuDetailFeignClient;
    @Autowired
    private ProductSkuDetailFeignCilent productSkuDetailFeignCilent;

    /**
     * @param skuId
     * @param model
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String item(@PathVariable("skuId") Long skuId, Model model) {
        //远程调用查询详情数据
        Result<SkuDetailVo> skuDetails = skuDetailFeignClient.getSkuDetailsBySkuId(skuId);
        SkuDetailVo detailVo = skuDetails.getData();
        if (detailVo != null) {
            //1、分类视图 {category1Id、category2Id、category3Id、category1Name、category2Name、category3Name}
            model.addAttribute("categoryView", detailVo.getCategoryView());

            //2、sku信息 {基本信息、图片列表}
            model.addAttribute("skuInfo", detailVo.getSkuInfo());

            //3、实时价格
            model.addAttribute("price", productSkuDetailFeignCilent.getPrice(skuId).getData());


            //4、所有销售属性集合
            model.addAttribute("spuSaleAttrList", detailVo.getSpuSaleAttrList());

            //5、valuesSkuJson
            model.addAttribute("valuesSkuJson", detailVo.getValuesSkuJson());

            //TODO 6、sku的规格；平台属性
        }

        return "item/index";
    }
}
